package com.htjx.mall.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.htjx.mall.commons.api.Result;
import com.htjx.mall.commons.models.product.Catalog;
import com.htjx.mall.services.CatalogService;

@Controller
@RequestMapping("/catalog")
public class CatalogController {
	@Autowired
	private CatalogService catalogService;
	/****
	 * 分页获取商品目录
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result list(@RequestParam("product_id") long productId) {
		List<Catalog> listCatalog = catalogService.SelectByProductId(productId);
		Result result = new Result(0, "查询成功");
		result.setBody(listCatalog);
		return result;
	}
	
	@RequestMapping(method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result selectById(@RequestParam("id") long id) {
		Catalog catalog = catalogService.selectById(id);
		Result result = new Result(0, "查询成功");
		result.setBody(catalog);
		return result;
	}
}
